package com.ucap.weking.guangan.fragments.fragmentContent;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.ucap.weking.guangan.R;
import com.ucap.weking.guangan.base.BaseFragment;
import com.ucap.weking.guangan.views.MyToast;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by weking on 2017/10/26.
 */

public class Phone12345Fragment extends BaseFragment {

    @InjectView(R.id.btn_call_12345)
    Button btnCall12345;
    public static int CALL_PHONE_12345_PERMISSION = 12345;
    @Override
    public void setData() {
        btnCall12345.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ContextCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.CALL_PHONE)
                        != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity(),
                            new String[]{Manifest.permission.CALL_PHONE},
                            CALL_PHONE_12345_PERMISSION);
                } else {
                    callPhone();
                }

            }
        });
    }

    private void callPhone() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:12345"));
        getActivity().startActivity(intent);
    }

    @Override
    public void intiView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.phone_12345_fagment, null);
        flContent.addView(view);
        ButterKnife.inject(this, view);

    }
}
